﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ProtocolConversion_WINCE
{
    class Memory
    {
        private static Form1 form1 = new Form1();
        //18可用空间//14中空间
        public static void SegmentMessage(byte[] date, int length, string cmd)
        {
            byte[] returnFrameCMDByte = new byte[2];
            //查询CMD 字典
            if (Form1.ReturnFrameCMDByteDic.TryGetValue(cmd, out returnFrameCMDByte))
            {
                //检查校验字
                //if (Form1.CompareDate(Converter.TakeOutByteNoOrder(date, length - 2, 2), Form1.CalculateCheckByte(date)))
                {
                    // uint dateTemp = (Converter.BytesToUInt32(date, 20) / (Converter.BytesToUInt32(date, 16)));

                    try
                    {
                        UInt32 x1 = BitConverter.ToUInt32(date, 20);
                        UInt32 x2 = BitConverter.ToUInt32(date, 16);

                        float dateTemp = (float)((float)1 - ((float)x1 / (float)x2));
                        byte[] temp = BitConverter.GetBytes(dateTemp);
                        //将数据填充到协议当中
                        //if (Form1.FillDate(Converter.TakeOutByteNoOrder(date, 20, 4), 18, 4))//18可用空间，4字节
                        Form1.FillDate(BitConverter.GetBytes(dateTemp), 18, 4);//18可用空间，4字节
                      
                    }
                    catch
                    {
                    }
                    
                }
            }
            else
            {
                //form1.textBox4.Text += "未从字典中提取到温度命令对应的数据\t\n";
            }
        }
    }
}
